//
// Created on 2024/6/26.
//
/*
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/

#include "ohos_eglContext_manage.h"

namespace webrtc {
namespace ohos {

uint16_t OhosEGLContextManage::desktopCnt_ {0};
uint16_t OhosEGLContextManage::drawCnt_ {0};
uint16_t OhosEGLContextManage::outputCnt_ {0};
OhosEGLContextManage OhosEGLContextManage::ohosEGLContextManage_;

GLuint OhosEGLContextManage::PopTextureID() {
    std::unique_lock<std::mutex> lock(queueMutex_);
    if (textureIDQueue_.empty()) {
        queueCond_.wait(lock, [this] { return !textureIDQueue_.empty(); });
    }

    GLuint textureID = textureIDQueue_.front();
    textureIDQueue_.pop();
    return textureID;
}

int32_t OhosEGLContextManage::PushTextureID(GLuint textureID) {
    std::lock_guard<std::mutex> lock(queueMutex_);
    textureIDQueue_.push(textureID);
    queueCond_.notify_one();
    return 0;
}

bool OhosEGLContextManage::TextureIDQueueEmpty() {
    std::lock_guard<std::mutex> lock(queueMutex_);
    return textureIDQueue_.empty();
}

} // namespace ohos
} // namespace webrtc